from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User, UserProfile

class UserAdmin(BaseUserAdmin):
    list_display = ('phone', 'role', 'role_authstatus', 'company', 'credit_score', 'date_joined')
    list_filter = ('role', 'role_authstatus', 'is_staff', 'is_superuser')
    fieldsets = (
        (None, {'fields': ('phone', 'password')}),
        ('个人信息', {'fields': ('role', 'avatar', 'company', 'credit_score', 'role_authstatus')}),
        ('权限', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
        ('重要日期', {'fields': ('last_login', 'date_joined')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('phone', 'role', 'password1', 'password2'),
        }),
    )
    search_fields = ('phone', 'company')
    ordering = ('phone',)
    readonly_fields = ('date_joined', 'last_login')

# 注册用户模型
admin.site.register(User, UserAdmin)

# 注册用户详细资料模型
@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'real_name', 'id_card', 'address')
    search_fields = ('user__phone', 'real_name', 'id_card')